package br.com.sigeu.loginuser;

import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.classic.Session;

import br.com.sigeu.loginuser.LoginUser;
import br.com.sigeu.loginuser.LoginUserDAO;

public class LoginUserDAOHibernate implements LoginUserDAO {

	private Session sessao;

	@Override
	public void salvar( LoginUser loginUser) {
		this.sessao.save(loginUser);

	}

	public Session getSessao() {
		return sessao;
	}

	public void setSessao(Session sessao) {
		this.sessao = sessao;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<LoginUser> listar() {
		Criteria lista = sessao.createCriteria(LoginUser.class);
		return lista.list();
	}
	
	@Override
	public void excluir(LoginUser loginUser) {
		this.sessao.delete(loginUser);

	}

	@Override
	public LoginUser pesquisar(String string) {
		Query consultaNome = this.sessao
				.createQuery("from LoginUser c where c.nome like :nome");
		consultaNome.setString("nome", "%" + string + "%");
		return (LoginUser) consultaNome.uniqueResult();
	}

	@Override
	public void alterar(LoginUser loginUser) {
		this.sessao.update(loginUser);
	}

}
